package com.roden.study.java.io;

import org.junit.Test;

import java.io.File;

/**
 * @Author luod
 * @create 2022/5/18 11:06
 */
public class FileTest {
    /**
     * Output of above program on Unix system:
     * File.separator = /
     * File.separatorChar = /
     * File.pathSeparator = :
     * File.pathSeparatorChar = :
     *
     * Output of the program on Windows system:
     * File.separator = \
     * File.separatorChar = \
     * File.pathSeparator = ;
     * File.pathSeparatorChar = ;
     */
    @Test
    public void fileSeparator(){
        System.out.println("File.separator = "+ File.separator);
        System.out.println("File.separatorChar = "+File.separatorChar);
        System.out.println("File.pathSeparator = "+File.pathSeparator);
        System.out.println("File.pathSeparatorChar = "+File.pathSeparatorChar);
    }

    @Test
    public void createLocalFile() throws Exception{
        String path="D:/temp";
        String fileName="/demo.txt";
        File file = new File(path, fileName);
        if(!file.exists()) {
            File parentFile=file.getParentFile();
            System.out.println(parentFile.getAbsolutePath());
            if(!parentFile.exists()) {
                file.getParentFile().mkdirs();
            }
            file.createNewFile();
        }
        System.out.println(file.getAbsolutePath());       
    }
}
